function S = spectrum2D(varargin)
% SYNTAX:
%  spectrum2D(spectrum): copy constructor
%  spectrum2D(XYmax, Lattice_Size, spectrum1,spectrum2,spectrum3,spectrum4)
%  spectrum2D(lpcvd_2DSurface)
%
switch nargin
    case 1
        if(isa(varargin{1},'spectrum2D'))
            S = varargin{1};
        end
    case 6
        S.XYmax = varargin{1};
        S.LatticeSize = varargin{2};
        S.z1 = varargin{3};
        S.z2 = varargin{4};
        S.z3 = varargin{4};
        S.z4 = varargin{4};   
        S.mode = size(S.z1,1)-1;     
                
        mode = S.mode;
        LatticeSize = S.LatticeSize;
        K1 = zeros(size(S.z1));
        K2 = zeros(size(S.z1));
        K3 = zeros(size(S.z1));
        K4 = zeros(size(S.z1));        
        for m=0:mode
            temp = 4*sin(pi*m/S.LatticeSize)^2/(S.XYmax^2);
            for n = 0:mode
                if(m==0||2*m==LatticeSize||n==0||2*n==LatticeSize)
                    K1(m+1,n+1) = 0.0;
                else
                    K1(m+1,n+1) = temp;
                end
                
                if(m==0)
                    K2(m+1,n+1) = 0.0;
                else
                    K2(m+1,n+1) = temp;
                end
                
                if(m==0||2*m==LatticeSize)
                    K3(m+1,n+1) = 0.0;
                else
                    K3(m+1,n+1) = temp;
                end
                
                if(n==0||2*n==LatticeSize||m==0)
                    K4(m+1,n+1) = 0.0;
                else
                    K4(m+1,n+1) = temp;
                end               
            end
        end
        S.K1 = K1;
        S.K2 = K2;
        S.K3 = K3;
        S.K4 = K4;
        S = class(S,'spectrum2D');
    otherwise
        error('Something wrong');
end



